package com;

import game.logic.Table.Position;
import game.logic.Table.TableSide;
import commands.Command;
import commands.LEDCommand;

/**
 * table connection class
 * 
 * Handles all communication with the table
 * current method = Standard input
 * 
 * possible upgrades: serial / bluetooth
 * 
 * @author jeff
 *
 */
public class TableConnection {
	ReceiveThread receiveThread;
	/**
	 * Constructor
	 */
	public TableConnection() {
		receiveThread = new ReceiveThread();
		beginReceiveThread();
	}
	
	/**
	 * begins the receive thread for table interrupts
	 */
	private void beginReceiveThread() {
		receiveThread.start();
	}
	
	public void sendCommand(Command command) {
		int c = encode(command);
	}
	
	private byte encode(Command command) {
		if (command.getType().equals("LEDCommand")) {
			LEDCommand c = (LEDCommand) command;
			byte retVal = 0;
			if (c.getSide() == TableSide.RIGHT) {
				retVal |= BuildFlags.RIGHTSIDE;
			}
			Integer pos =  Position.getIndexFromEnum(c.getPos());
			byte p = pos.byteValue();
			p &= 0x0f;
			
			retVal |= p;
			
			
		}
		return 0;
	}
}
